/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('appstream-center', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetMqttTicketRequest {
  clientOS?: string(name='ClientOS'),
  clientType?: int32(name='ClientType'),
  clientVersion?: string(name='ClientVersion'),
  loginToken?: string(name='LoginToken'),
  sessionId?: string(name='SessionId'),
  uuid?: string(name='Uuid'),
}

model GetMqttTicketResponseBody = {
  code?: string(name='Code'),
  expireTimeStamp?: string(name='ExpireTimeStamp'),
  message?: string(name='Message'),
  mqttEndpoint?: string(name='MqttEndpoint'),
  mqttGroupId?: string(name='MqttGroupId'),
  mqttInstanceId?: string(name='MqttInstanceId'),
  mqttPassword?: string(name='MqttPassword'),
  mqttUsername?: string(name='MqttUsername'),
  mqttVPCEndpoint?: string(name='MqttVPCEndpoint'),
  requestId?: string(name='RequestId', description='Id of the request'),
  success?: string(name='Success'),
  topicList?: string(name='TopicList'),
}

model GetMqttTicketResponse = {
  headers: map[string]string(name='headers'),
  body: GetMqttTicketResponseBody(name='body'),
}

async function getMqttTicketWithOptions(request: GetMqttTicketRequest, runtime: Util.RuntimeOptions): GetMqttTicketResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.clientOS)) {
    body['ClientOS'] = request.clientOS;
  }
  if (!Util.isUnset(request.clientType)) {
    body['ClientType'] = request.clientType;
  }
  if (!Util.isUnset(request.clientVersion)) {
    body['ClientVersion'] = request.clientVersion;
  }
  if (!Util.isUnset(request.loginToken)) {
    body['LoginToken'] = request.loginToken;
  }
  if (!Util.isUnset(request.sessionId)) {
    body['SessionId'] = request.sessionId;
  }
  if (!Util.isUnset(request.uuid)) {
    body['Uuid'] = request.uuid;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetMqttTicket',
    version = '2022-02-10',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'Anonymous',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getMqttTicket(request: GetMqttTicketRequest): GetMqttTicketResponse {
  var runtime = new Util.RuntimeOptions{};
  return getMqttTicketWithOptions(request, runtime);
}

